import 'babel-polyfill'
import 'classlist-polyfill'
import Vue from 'vue'
import axios from './router/axios'
import VueAxios from 'vue-axios'
import App from './App'
import './permission' // 权限
import './error' // 日志
import router from './router/router'
import store from './store'
import { loadStyle } from './util/util'
import * as urls from '@/config/env'
import { iconfontUrl, iconfontVersion } from '@/config/env'
import * as filters from './filters' // 全局filter
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import './styles/common.scss'
import avueFormDesign from 'avue-plugin-formdesign'
import basicContainer from './components/basic-container/main'
// 插件 json 展示
import vueJsonTreeView from 'vue-json-tree-view'

import Distpicker from 'v-distpicker'  //省市区
Vue.component('v-distpicker', Distpicker)

Vue.use(router)

Vue.use(avueFormDesign);
Vue.use(vueJsonTreeView)

Vue.use(VueAxios, axios)

Vue.use(ElementUI, {
  size: 'medium',
  menuType: 'text'
})

Vue.use(window.AVUE, {
  size: 'medium',
  menuType: 'text'
})

// 注册全局容器
Vue.component('basicContainer', basicContainer)

// 加载相关url地址
Object.keys(urls).forEach(key => {
  Vue.prototype[key] = urls[key]
})

// 加载过滤器
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

// 动态加载阿里云字体库
iconfontVersion.forEach(ele => {
  loadStyle(iconfontUrl.replace('$key', ele))
})

Vue.config.productionTip = false

Vue.prototype.distinct = (arr, key) => {  //数组去重
  var newobj = {}, newArr = [];
  for (var i = 0; i < arr.length; i++) {
    var item = arr[i];
    if (!newobj[item[key]]) {
      newobj[item[key]] = newArr.push(item);
    }
  }
  return newArr;
}

import compressImg from './util/compressImg.js' //压缩图片质量
Vue.prototype.$compressImg = compressImg   //注册为全局变量

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
